//! 图形用户界面模块

mod window;
pub use window::MainWindow;

mod resources;
pub use resources::*;

mod event_handler;
pub use event_handler::*;

/// 初始化 GUI 应用
pub fn init() -> Result<(), slint::PlatformError> {
    MainWindow::register_global();
    Ok(())
}

/// GUI 状态管理
#[derive(Default)]
pub struct GuiState {
    pub selected_pkg_type: String,
    pub package_list: Vec<PackageInfo>,
    pub installation_progress: f32,
}

/// 包信息结构
#[derive(Clone, Debug)]
pub struct PackageInfo {
    pub name: String,
    pub version: String,
    pub installed: bool,
    pub file_path: String,
}

impl slint::Model for PackageInfo {
    type Data = slint::ModelRc<slint::StandardListViewItem>;

    fn row_count(&self) -> usize {
        1
    }

    fn row_data(&self, row: usize) -> Option<Self::Data> {
        if row == 0 {
            Some(slint::ModelRc::new(slint::VecModel::from(vec![
                slint::StandardListViewItem::from(self.name.clone()),
                slint::StandardListViewItem::from(self.version.clone()),
            ])))
        } else {
            None
        }
    }
}